package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.SystemDictionary;
import cn.wolfcode.rbac.domain.SystemDictionaryItem;
import cn.wolfcode.rbac.mapper.SystemDictionaryItemMapper;
import cn.wolfcode.rbac.mapper.SystemDictionaryMapper;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.query.SystemDictionaryItemQuery;
import cn.wolfcode.rbac.service.ISystemDictionaryItemService;
import cn.wolfcode.rbac.service.ISystemDictionaryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SystemDictionaryItemServiceImpl implements ISystemDictionaryItemService {
    @Autowired
    private SystemDictionaryItemMapper systemDictionaryItemMapper;
    @Override
    @Transactional(readOnly = true)
    public PageInfo query(SystemDictionaryItemQuery qo) {
        /*Integer rows = Integer.valueOf(this.departmentMapper.selectForCount(paramQueryObject));
        if (rows.intValue()==0){
            return new PageResult(Integer.valueOf(paramQueryObject.getPageSize()));
        }
        List<Department> list = this.departmentMapper.selectForList(paramQueryObject);
        return new PageResult(Integer.valueOf(paramQueryObject.getCurrentPage()),rows,list,Integer.valueOf(paramQueryObject.getPageSize()));*/
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<SystemDictionaryItem> list = this.systemDictionaryItemMapper.selectForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(SystemDictionaryItem entity) {
        if(entity.getId()==null){
            this.systemDictionaryItemMapper.insert(entity);
        }else {
            this.systemDictionaryItemMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public void delete(Long paramLong) {
        this.systemDictionaryItemMapper.deleteByPrimaryKey(paramLong);
    }

    @Override
    @Transactional(readOnly = true)
    public SystemDictionaryItem get(Long paramLong) {
        return this.systemDictionaryItemMapper.selectByPrimaryKey(paramLong);
    }

    @Override
    @Transactional(readOnly = true)
    public List<SystemDictionaryItem> list() {
        return this.systemDictionaryItemMapper.selectAll();
    }

    @Override
    public List<SystemDictionaryItem> findFromSDI(Integer parent_id) {
        return this.systemDictionaryItemMapper.findJobsOrSources(parent_id);
    }


}
